package com.team.recruitment_management_system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.team.recruitment_management_system.mapper.CompanyMapper;
import com.team.recruitment_management_system.pojo.dto.company.AddBusinessInformationDto;
import com.team.recruitment_management_system.pojo.dto.company.ChangeBusinessInformationDto;
import com.team.recruitment_management_system.pojo.entity.BusinessInformation;
import com.team.recruitment_management_system.pojo.entity.Company;
import com.team.recruitment_management_system.service.BusinessInformationService;
import com.team.recruitment_management_system.mapper.BusinessInformationMapper;
import com.team.recruitment_management_system.util.result.Result;
import com.team.recruitment_management_system.util.result.ResultCodeEnum;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 86147
* @description 针对表【business_information(工商信息表)】的数据库操作Service实现
* @createDate 2024-03-21 20:28:40
*/
@Service
public class BusinessInformationServiceImpl extends ServiceImpl<BusinessInformationMapper, BusinessInformation>
    implements BusinessInformationService{

    @Autowired
    private CompanyMapper companyMapper;

    @Override
    public Result<Void> addBusinessInformation(AddBusinessInformationDto addBusinessInformationDto) {
        Company company = companyMapper.selectById(addBusinessInformationDto.getCompanyId());
        if(company == null){
            return Result.build(null, ResultCodeEnum.COMPANY_ERROR);
        }
        LambdaQueryWrapper<BusinessInformation> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BusinessInformation::getCompanyId,addBusinessInformationDto.getCompanyId());
        if(this.exists(queryWrapper)){
            return Result.build(null, ResultCodeEnum.BUSINESS_INFORMATION_ERROR);
        }
        BusinessInformation businessInformation = new BusinessInformation();
        BeanUtils.copyProperties(addBusinessInformationDto,businessInformation);
        this.save(businessInformation);
        return Result.postOk(null);
    }

    @Override
    public Result<Void> changeBusinessInformation(ChangeBusinessInformationDto changeBusinessInformationDto) {
        BusinessInformation businessInformation = this.getById(changeBusinessInformationDto.getId());
        if(businessInformation == null){
            return Result.build(null, ResultCodeEnum.INFORMATION_NOT_EXIST_ERROR);
        }
        BeanUtils.copyProperties(changeBusinessInformationDto,businessInformation);
        this.updateById(businessInformation);
        return Result.putOk(null);
    }
}




